package sdk.webview.fmc.com.fmcsdk.check.persenter;

import sdk.webview.fmc.com.fmcsdk.base.BasePresenter;
import sdk.webview.fmc.com.fmcsdk.base.UserApi;
import sdk.webview.fmc.com.fmcsdk.bean.ApprovalFullLogBean;
import sdk.webview.fmc.com.fmcsdk.bean.UcWfTaskDetailBean;
import sdk.webview.fmc.com.fmcsdk.bean.WfEntityDetailBean;
import sdk.webview.fmc.com.fmcsdk.check.interfaces.ApprovalAcceptanceHistoryView;
import sdk.webview.fmc.com.fmcsdk.util.Url;
import sdk.webview.fmc.com.fmcsdk.util.UserHelper;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.observer.ResponseTransformer;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.subscriber.ResponseSubscriber;

public class ApprovalAcceptanceHistoryPresenter extends BasePresenter<ApprovalAcceptanceHistoryView> {


    public void getUcWfTaskDetail(String projId, String ownerId) {
        view.showLoading();
        getApi(UserApi.class).getUcWfTaskDetail(
                        getDefaultAddress() + Url.GET_UC_WF_TASK_DETAIL,
                        UserHelper.getToken(),
                        projId,ownerId)
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<UcWfTaskDetailBean>() {
                    @Override
                    public void success(UcWfTaskDetailBean baseData) {
                        view.getUcWfTaskDetailSuccess(baseData);
                        view.hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.hideLoading();
                    }

                    @Override
                    public void onRequestAgain() {
                    }


                });

    }

    public void getWfEntityDetail(String projId, String wfEntityId) {
        view.showLoading();
        getApi(UserApi.class).getWfEntityDetail(
                        getDefaultAddress() + Url.GET_UC_WF_ENTITY_DETAIL,
                        UserHelper.getToken(),
                        projId,wfEntityId)
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<WfEntityDetailBean>() {
                    @Override
                    public void success(WfEntityDetailBean baseData) {
                        view.getWfEntityDetailSuccess(baseData);
                        view.hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.hideLoading();
                    }

                    @Override
                    public void onRequestAgain() {
                    }


                });

    }


    public void getApprovalFullLog(String projId, String wfEntityId) {
        view.showLoading();
        getApi(UserApi.class).getApprovalFullLog(
                        getDefaultAddress() + Url.GET_UC_WF_getApprovalFullLog,
                        UserHelper.getToken(),
                        projId,wfEntityId)
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<ApprovalFullLogBean>() {
                    @Override
                    public void success(ApprovalFullLogBean baseData) {
                        view.getApprovalFullLogSuccess(baseData);
                        view.hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.hideLoading();
                    }

                    @Override
                    public void onRequestAgain() {
                    }


                });

    }
}
